students = [
    {'name': 'Tom', 'age': 20},
    {'name': 'Rose', 'age': 19},
    {'name': 'Jack', 'age': 22}
]

def get_name(d):
    return d['name']

# 要求对上面容器进行排序.规则是按照名字.
# students.sort() # TypeError: '<' not supported between instances of 'dict' and 'dict'
# print(students)

# students.sort(key=lambda d:d['name'])
students.sort(key=get_name)
print(students)

# 按照年龄升序排序.
students.sort(key=lambda d:d['age'])
print(students)

# 按照年龄降序排序.
students.sort(key=lambda d:d['age'],reverse=True)
print(students)